package com.srs.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class StringUtil {
	public static String convert(String st) {
		String st1 = st;
		st1 = st.replaceAll("_a", "A");
		st = st1.replaceAll("_b", "B");
		st1 = st.replaceAll("_c", "C");
		st = st1.replaceAll("_d", "D");
		st1 = st.replaceAll("_e", "E");
		st = st1.replaceAll("_f", "F");
		st1 = st.replaceAll("_g", "G");
		st = st1.replaceAll("_h", "H");
		st1 = st.replaceAll("_i", "I");
		st = st1.replaceAll("_j", "J");
		st1 = st.replaceAll("_k", "K");
		st = st1.replaceAll("_l", "L");
		st1 = st.replaceAll("_m", "M");
		st = st1.replaceAll("_n", "N");
		st1 = st.replaceAll("_o", "O");
		st = st1.replaceAll("_p", "P");
		st1 = st.replaceAll("_q", "Q");
		st = st1.replaceAll("_r", "R");
		st1 = st.replaceAll("_s", "S");
		st = st1.replaceAll("_t", "T");
		st1 = st.replaceAll("_u", "U");
		st = st1.replaceAll("_v", "V");
		st1 = st.replaceAll("_w", "W");
		st = st1.replaceAll("_x", "X");
		st1 = st.replaceAll("_y", "Y");
		st = st1.replaceAll("_z", "Z");
		return st;
	}

	public static List<String> returnDatesOfBeforeWeek(String date){
		List<String> dates = new ArrayList<String>();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
			java.util.Date curDate = dateFormat.parse(date);
			for(int i=7; i>0; i--){
				java.util.Date nextDate = new Date(curDate.getTime() - 1000*60*60*24*i);
				dates.add(dateFormat.format(nextDate));
			}
//			for (String string : dates) {
//				System.out.println(string);
//			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dates;
	}
	
	public static List<Date> returnDatesOfBeforeWeekDate(String date){
		List<Date> dates = new ArrayList<Date>();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
			java.util.Date curDate = dateFormat.parse(date);
			for(int i=7; i>0; i--){
				java.util.Date nextDate = new Date(curDate.getTime() - 1000*60*60*24*i);
				dates.add(nextDate);
			}
//			for (String string : dates) {
//				System.out.println(string);
//			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dates;
	}	
	
	public static List<Date> returnDatesBetweenDate(String fromDate, String toDate){
		List<Date> dates = new ArrayList<Date>();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
			java.util.Date fDate = dateFormat.parse(fromDate);
			java.util.Date tDate = dateFormat.parse(toDate);
			Long count = ((tDate.getTime() - fDate.getTime())/(1000*60*60*24)); 
			for(int i=0; i<=count; i++){
				java.util.Date nextDate = new Date(fDate.getTime() + 1000*60*60*24*i);
				dates.add(nextDate);
			}
//			for (String string : dates) {
//				System.out.println(string);
//			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dates;
	}		
	
	public static List<String> returnDatesBetween(String fromDate, String toDate){
		List<String> dates = new ArrayList<String>();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
			java.util.Date fDate = dateFormat.parse(fromDate);
			java.util.Date tDate = dateFormat.parse(toDate);
			Long count = ((tDate.getTime() - fDate.getTime())/1000); 
			for(int i=0; i>count; i--){
				java.util.Date nextDate = new Date(fDate.getTime() - 1000*60*60*24*i);
				dates.add(dateFormat.format(nextDate));
			}
//			for (String string : dates) {
//				System.out.println(string);
//			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dates;
	}	
	
	public static boolean existInList(String key, String[] array){
		for(int i=0; i<array.length; i++){
			if (key.equalsIgnoreCase(array[i])){
				return true;
			}
		}
		return false;
	}
	
	public static void main(String[] args) {
		StringUtil.returnDatesOfBeforeWeek("2009-03-2");
		System.out.println(StringUtil.convert("	agent_parameter_id	"));
		System.out.println(StringUtil.convert("	agent_parameter_name	"));
		System.out.println(StringUtil.convert("	enable_mocc	"));
		System.out.println(StringUtil.convert("	enable_nic_by_user_activation	"));
		System.out.println(StringUtil.convert("	enable_nic_by_schedule	"));
		System.out.println(StringUtil.convert("	enable_nic_by_call_end	"));
		System.out.println(StringUtil.convert("	sc	"));
		System.out.println(StringUtil.convert("	time_begin	"));
		System.out.println(StringUtil.convert("	duration	"));
		System.out.println(StringUtil.convert("	number_of_collections	"));


	}
}
